package streamAPI.operators;

import org.apache.flink.api.java.tuple.Tuple3;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.testng.annotations.Test;


/**
 * @author yue.cao
 * @since 09-28-2020
 */
public class DemoWithMax {

	@Test(description = "max 如果出现多个属性 其实没有用到的属性只记录第一次")
	public void demoWithMax() throws Exception{
		StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
		DataStreamSource<Tuple3<String, String, Integer>> source = env.fromElements(
				Tuple3.of("A", "aa", 0),
				Tuple3.of("B", "aa", 1),
				Tuple3.of("A", "bb", 2)
		);
		source.keyBy(0).max(2).print();
		env.execute();
	}

	@Test(description = "maxBy 不仅返回分组字段 也会返回其他字段")
	public void demoWithMaxBy() throws Exception{
		StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
		DataStreamSource<Tuple3<String, String, Integer>> source = env.fromElements(
				Tuple3.of("A", "aa", 0),
				Tuple3.of("B", "aa", 1),
				Tuple3.of("A", "bb", 2)
		);
		source.keyBy(0).maxBy(2).print();
		env.execute();
	}

}
